<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link
      href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.15.3/css/all.css"
      rel="stylesheet"
    />
    <style>
      body {
        background-color: rgb(171, 201, 171);
        display: flex;
        align-items: center;
        justify-content: center;
      }
      .button {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        position: relative;
        display: flex;
        align-items: center;
        justify-content: center;
        width: 160px;
        height: 40px;
        color: black;
        background: white;
        border-radius: 10px;
        margin: 0 15px;
        font-size: 18px;
        text-decoration: none;
        overflow: hidden;
      }
      .progress {
        content: "";
        position: absolute;
        top: 90%;
        left: -100%;
        width: 100%;
        height: 100%;
        background: #4776e6;
        background: -webkit-linear-gradient(to right, #8e54e9, #4776e6);
        background: linear-gradient(to right, #8e54e9, #4776e6);
        transition: all 4s;
      }
      .text {
        z-index: 10;
      }
      i {
        margin: 0 8px 0 0;
        font-size: 16px;
        z-index: 10;
      }
      @keyframes tapDownload {
        0% {
          transform: translateY(2px);
        }
        100% {
          transform: translateY(0);
        }
      }

      .fa-arrow-down {
        animation: tapDownload 1s ease infinite;
      }

      @keyframes downloading {
        0% {
          transform: scale(0.7);
        }
        100% {
          transform: scale(1);
        }
      }

      .fa-download {
        animation: downloading 1s ease infinite alternate-reverse;
      }
    </style>
  </head>
  <body>
    <div class="button">
      <span class="text"
        ><i class="fa fa-arrow-down" aria-hidden="true"></i>download</span
      >
      <span class="progress"></span>
    </div>
  </body>
</html>
<script>
  const btn = document.querySelectorAll(".button")[0];
  const pr = document.querySelectorAll(".progress")[0];
  const text = document.querySelectorAll(".text")[0];
  const icon = document.querySelectorAll(".fa")[0];
  btn.addEventListener("click", () => {
    pr.style.left = "0";
    icon.classList.remove("fa-arrow-down");
    icon.classList.add("fa-download");
    text.innerText = "downloading";
    setTimeout(() => {
      // 忽略了一些代码
      icon.style.color = "white";
      icon.classList.remove("fa-download");
      icon.classList.add("fa-check");
    }, 4000);
  });
</script>
